<template>
  <div class="login-body">
    <div class="login-container">
      <div class="head">
        <img
          class="logo"
          src="https://s.weituibao.com/1582958061265/mlogo.png"
        />
        <div class="name">
          <div class="title">新蜂商城</div>
          <div class="tips">Vue3.0 后台管理系统</div>
        </div>
      </div>
      <el-form label-position="top" ref="loginForm" class="login-form">
        <el-form-item label="账号" prop="username">
          <el-input
            type="text"
            v-model="username"
            autocomplete="off"
            @blur="ts1"
          ></el-input>
          <div class="ts" v-show="show1">用户名不能为空</div>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input
            type="password"
            v-model="password"
            autocomplete="off"
            @blur="ts2"
          ></el-input>
          <div class="ts" v-show="show2">密码不能为空</div>
        </el-form-item>
        <el-form-item>
          <div style="color: #333">登录表示您已同意<a>《服务条款》</a></div>
          <el-button style="width: 100%" type="primary" @click="loagin">立即登录</el-button>
          <el-checkbox v-model="checked" @change="!checked"
            >下次自动登录</el-checkbox
          >
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      checked: true,
      username: "admin",
      password: "123456",
      show1: false,
      show2: false,
    };
  },
  methods: {
    loagin(){
      this.$http.post("/login", { username: this.username, password: this.password })
      .then((res)=>{
        console.log(res);
        if(res.meta.status == 200){
          localStorage.setItem("token",res.data.token);
          this.$router.push("/About");
          this.$message({
            message:res.meta.msg,
            type:"success",
          });
        }else{
          this.$message({
            message:res.meta.status,
            type:"error"
            })
        }
      })
    },
     //login用户密码的判断
    ts1() {
      if (this.username == "") {
        this.show1 = true;
      }
    },
    ts2() {
      if (this.password == "") {
        this.show2 = true;
      }
    },
  },
    watch: {
    username() {
      this.show1 = false;
    },
    password() {
      this.show2 = false;
    },
  },
};
</script>

<style scoped>
.login-body {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 100px;
  width: 100%;
  background-color: #fff;
  /* background-image: linear-gradient(25deg, #077f7c, #3aa693, #5ecfaa, #7ffac2); */
}
.login-container {
  width: 420px;
  height: 500px;
  background-color: #fff;
  border-radius: 4px;
  box-shadow: 0px 21px 41px 0px rgba(0, 0, 0, 0.2);
}
.head {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 40px 0 20px 0;
}
.head img {
  width: 100px;
  height: 100px;
  margin-right: 20px;
}
.head .title {
  font-size: 28px;
  color: #1baeae;
  font-weight: bold;
}
.head .tips {
  font-size: 12px;
  color: #999;
}
.login-form {
  width: 70%;
  margin: 0 auto;
}
.ts {
  font-size: 12px;
  height: 5px;
  color: red;
}
</style>
<style>
.el-form--label-top .el-form-item__label {
  padding: 0;
}
.login-form .el-form-item {
  margin-bottom: 12px;
}

</style>
